using System;
using NodeCanvas.Framework;
using ParadoxNotion.Design;

namespace Yoozoo.Gameplay.Liberty.AI.Node
{
    [Category("Ggame/Liberty")]
    public class HasTriggerNpcBehavior : AIConditionBaseNode
    {
        public static Action<int,string> OnTriggerNpcBehavior;

        public BBParameter<string> actionValue;

        private bool _success = false;
        protected override void OnEnable()
        {
            base.OnEnable();

            OnTriggerNpcBehavior += OnTriggerNpcBehaviorFunc;
        }

        private void OnTriggerNpcBehaviorFunc(int uniqueId,string action)
        {
            if (uniqueId == _entity.data.uniqueId)
            {
                _success = true;
                actionValue.SetValue(action);
            }
        }

        protected override bool OnCheck()
        {
            if (_success)
            {
                _success = false;
                return true;
            }
            return false;
        }
        
        
        protected override void OnDisable()
        {
            base.OnDisable();
            OnTriggerNpcBehavior -= OnTriggerNpcBehaviorFunc;
        }
    }
}